package com.fzkj.bio.消息群发;

import com.fzkj.bio.fileupload.ServerReadThread;
import com.fzkj.bio.消息群发.factory.ClientFactory;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * 实现消息群发给客户端
 */
public class Server {

    public static void main(String[] args) {
        startServer();
    }

    /**
     * 启动服务端，监听客户端连接
     */
    private static void startServer(){
        try{
            ServerSocket ss = new ServerSocket(2323);
            System.out.println("== 服务端启动成功 ==");
            while(true) {
                Socket s = ss.accept();
                // 将新连接的客户端添加到容器中
                ClientFactory.addClient(s);
                new Thread(new ServerReadThread(s)).start();
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
